<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<!-- 2、
/* 请实现一个函数，统计数组里字符的出现次数，例如：
var arr = [‘a’,’a’,’a’,’b’,’b’,’c’];
var ret = analyse(arr);
//结果：ret = {
  a: 3,
  b: 2,
  c: 1
}
*/ -->

<body>
    <div>test14-2</div>
    <script>
        var arr = ['a', 'a', 'a', 'b', 'b', 'c'];
        function analyse(arr) {
            let ret = {}
            for (let i = 0; i < arr.length; i++) {
                if (ret[arr[i]]) {
                    ret[arr[i]]++
                } else {
                    ret[arr[i]] = 1
                }
            }
            console.log(ret)
        }
        var ret = analyse(arr);
    </script>
</body>

</html>